import logging

from datetime import datetime
from flask import Flask, jsonify
from flask_cors import CORS
from config import settings
from flask_migrate import Migrate
from api.api_user import bp as user_bp
from api.api_cmaParams import bc
import models  # 不能删除
from exts import db, ma
app = Flask(__name__)
CORS(app)  # 允许所有跨域请求
app.config.from_object(settings)


# 配置
db.init_app(app)
ma.init_app(app)
# 添加命令
migrate = Migrate(app, db)

# 蓝图注册
app.register_blueprint(user_bp)
app.register_blueprint(bc)
# 配置日志记录
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('sqlalchemy.engine')
logger.setLevel(logging.INFO)


@app.route("/", methods=["GET"])
def hello():
    current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    return jsonify({
        "message": "测试数据!",
        "state": "success",
        "时间 Local Time": datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
        "UTC Time": datetime.utcnow(),
    })


# flask  直接在代码里面创建表
# 当前文件做为主入口运行
if __name__ == '__main__':
    app.run(host=settings.LOCAL_HOST, port=settings.LOCAL_PORT)
